package com.yisu.expressway.utils;

import android.content.Context;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.google.gson.reflect.TypeToken;
import com.yisu.expressway.R;
import com.yisu.expressway.application.ExApplication;
import com.yisu.expressway.network.ApiClientHelper;
import com.yisu.expressway.network.ApiResult;
import com.yisu.expressway.network.ApiSetting;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;


/**
 * Created by Yue Zhen on 2016/2/20.
 */
public class SMSUtil {
    private static final String TAG = "SMSUtil";

    public interface SMSListener{
        void success();
        void error();
    }

    public static void sendSmsRequest(final SMSListener listener,
                                      final String phoneNumber) {

        Map<String, Object> params = new HashMap();
        params.put("phoneNumber", phoneNumber);

        ApiClientHelper.postApi(ApiSetting.getVerifyCode(), new TypeToken<Object>() {
        }, new JSONObject(params), new Response.Listener<ApiResult<Object>>() {
            @Override
            public void onResponse(ApiResult<Object> result) {
                if (!result.success) {
                    ToastUtil.displayLongToastMsg(ExApplication.getInstance().getApplicationContext(), result.getMsg());
                    return;
                }

                ToastUtil.displayLongToastMsg(ExApplication.getInstance().getApplicationContext(), R.string.verification_code_send_success);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {

            }
        }, TAG);

    }
}
